package com.hibase.core.rule.web.ruletable;

import com.github.pagehelper.PageInfo;
import com.hibase.common.entity.ResponseModel;
import com.hibase.common.util.EntityUtil;
import com.hibase.core.rule.entity.ruletable.RuleTableData;
import com.hibase.core.rule.entity.ruletable.vo.*;
import com.hibase.core.rule.service.ruletable.RuleTableDataService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 动态规则数据表 前端控制器
 * </p>
 *
 * @author hufeng
 * @since 2019-06-10
 */
@RestController
@RequestMapping("/rule-table-data")
@Api(tags = "动态规则数据表")
@Deprecated
public class RuleTableDataController{

    @Autowired
    private RuleTableDataService ruleTableDataService;

    @ApiOperation(value = "查询动态规则数据表列表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectRuleTableDataList")
    public ResponseModel<RuleTableDataListVO> selectRuleTableDataList(@RequestBody RuleTableDataSearchVO searchVO) {

        PageInfo result = ruleTableDataService.selectRuleTableDataList(searchVO);

        result.setList(EntityUtil.transform(result.getList(), RuleTableDataListVO.class));

        return ResponseModel.successMsg(result);
    }

    @ApiOperation(value = "新增动态规则数据表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "insertRuleTableData")
    public ResponseModel<String> insertRuleTableData(@RequestBody RuleTableDataInsertVO insertVO) {

        RuleTableData entity = EntityUtil.transform(insertVO, RuleTableData.class);

        ruleTableDataService.saveRuleTableData(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "修改动态规则数据表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateRuleTableData")
    public ResponseModel<String> updateRuleTableData(@RequestBody RuleTableDataUpdateVO updateVO) {

        RuleTableData entity = EntityUtil.transform(updateVO, RuleTableData.class);

        ruleTableDataService.saveRuleTableData(entity);

        return ResponseModel.successMsg(entity.getId());
    }

    @ApiOperation(value = "查询动态规则数据表详情", httpMethod = "POST")
    @HibasePostRequestMapping(value = "viewRuleTableDataDetails")
    public ResponseModel<RuleTableDataViewVO> viewRuleTableDataDetails(@RequestBody OperationIdEntity operationidEntity) {

        return ResponseModel.successMsg(EntityUtil.transformByJson(ruleTableDataService.viewRuleTableData(operationidEntity.getId()), RuleTableDataViewVO.class));
    }

    @ApiOperation(value = "删除动态规则数据表记录", httpMethod = "POST")
    @HibasePostRequestMapping(value = "/deleteRuleTableData")
    public ResponseModel<String> deleteRuleTableData(@RequestBody OperationIdEntity delete) {

        ruleTableDataService.deleteRuleTableData(delete.getId());

        return ResponseModel.successMsg();
    }
}
